#ifndef PROCESSDIALOG_H
#define PROCESSDIALOG_H

#include <QDialog>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
#include <QComboBox>
#include <QDoubleSpinBox>
#include <QPushButton>
#include <QMessageBox>
#include <QSqlQuery>
#include <QSqlError>
#include <QRegExpValidator>
#include <QDebug>

class ProcessDialog : public QDialog
{
    Q_OBJECT

public:
    explicit ProcessDialog(QWidget *parent = nullptr);
    ProcessDialog(const QString &processId, QWidget *parent = nullptr);
    ~ProcessDialog();

    // 获取工序信息
    QString getProcessId() const;
    QString getProcessName() const;
    QString getDescription() const;
    double getPieceRate() const;
    int getDepartmentId() const;

    // 设置工序信息（用于编辑模式）
    void setProcessInfo(const QString &processId, const QString &name, 
                       const QString &description, double pieceRate, 
                       int departmentId);

private slots:
    void accept() override;
    void reject() override;
    void onProcessIdChanged();

private:
    void setupUI();
    void setupConnections();
    void loadDepartments();
    bool validateInput();
    void generateProcessId();
    bool isProcessIdExists(const QString &processId);

    // UI组件
    QLineEdit *m_processIdEdit;
    QLineEdit *m_nameEdit;
    QTextEdit *m_descriptionEdit;
    QDoubleSpinBox *m_pieceRateSpinBox;
    QComboBox *m_departmentCombo;
    QPushButton *m_generateIdBtn;
    QPushButton *m_okBtn;
    QPushButton *m_cancelBtn;

    // 数据
    bool m_isEditMode;
    QString m_originalProcessId;
    QMap<QString, int> m_departmentMap; // 班组名称 -> ID映射
};

#endif // PROCESSDIALOG_H